home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Drawing / TemporaryPort.cp < prev    next >
Encoding:
Text File  |  1997-06-28  |  870 b   |  50 lines  |  [TEXT/CWIE]

  1. // TemporaryPort.cp
  2.  
  3. #ifndef TemporaryPort_h
  4. #include "TemporaryPort.h"
  5. #endif
  6. #ifndef GrafPortObject_h
  7. #include "GrafPortObject.h"
  8. #endif
  9. #ifndef QuickDrawError_h
  10. #include "QuickDrawError.h"
  11. #endif
  12.  
  13. bool TemporaryPort::sharedPortBusy = false;
  14.  
  15. TemporaryPort::TemporaryPort()
  16.   : old( GrafPortObject::Current() )
  17.   {
  18.     if ( sharedPortBusy )
  19.       {
  20.         OpenCPort( &personal );
  21.         
  22.         toUse = reinterpret_cast<GrafPortObject *>( &personal );
  23.         QuickDrawError::Check().Throw();
  24.       }
  25.      else
  26.       {
  27.         static GrafPortObject sharedPort;
  28.         toUse = &sharedPort;
  29.         sharedPortBusy = true;
  30.       }
  31.     
  32.     toUse->BeCurrent();
  33.   }
  34.  
  35. TemporaryPort::~TemporaryPort()
  36.   {
  37.     old.BeCurrent();
  38.     
  39.     if ( toUse == reinterpret_cast<GrafPortObject *>( &personal ) )
  40.       {
  41.         CloseCPort( &personal );
  42.         QuickDrawError::Check().Throw();
  43.       }
  44.      else
  45.       {
  46.         Assert( sharedPortBusy );
  47.         sharedPortBusy = false;
  48.       }
  49.   }
  50.